package com.xuxiao.simple;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;

public class DiscardClientHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        // Discard the received data silently.
        ByteBuf b = (ByteBuf) msg;
        System.out.println("读取到server的数据:"+ctx.channel().remoteAddress()+"==============:"+b.toString(CharsetUtil.UTF_8));
    }

    @Override
    public void  channelActive(ChannelHandlerContext ctx) {
        // Close the connection when an exception is raised.
        ctx.writeAndFlush(Unpooled.copiedBuffer("我发送请求到server",CharsetUtil.UTF_8));
    }

}